package cvc.framework.service;

import com.alibaba.fastjson.JSONObject;
import cvc.framework.entity.CustomerMes;
import cvc.framework.webSocket.WebSocket;
import org.springframework.stereotype.Service;


@Service
public class FunctionService {


    public boolean rtmpLive(String cameraId, Boolean checked) {
        boolean ws = WebSocket.sendMessageToUser("" + cameraId, "rtmpLive#" + checked);
        return ws;
    }

    public boolean laserSwitch(String cameraId, Boolean checked) {
        boolean ws = WebSocket.sendMessageToUser("" + cameraId, "laserSwitch#" + checked);
        return ws;
    }

    public boolean recognitionSwitch(String cameraId, Boolean checked) {
        boolean ws = WebSocket.sendMessageToUser("" + cameraId, "recognitionSwitch#" + checked);
        return ws;
    }

    public JSONObject allSwitch(String cameraId) {
        boolean ws = WebSocket.sendMessageToUser(cameraId, "allSwitch#allSwitch");
        if (ws) {
            while (true) {
                boolean contains = CustomerMes.customerMessage.containsKey("allSwitch");
                if (contains) {
                    String allSwitch = CustomerMes.customerMessage.get("allSwitch");
                    JSONObject jsonSwitch = JSONObject.parseObject(allSwitch);
                    CustomerMes.customerMessage.remove("allSwitch");
                    return jsonSwitch;
                }
            }
        }
        return null;
    }
}
